// 根据路由path递归查询选项卡
export const loopSearchArr = (tabs, path, breadCrumbArr, type, chilArr) => {
    for(var i in tabs){
        if(type){
            breadCrumbArr = []// 第一层循环需要清空数组， 后续递归循环不需要
            breadCrumbArr.push({
                path: tabs[i].path,
                name: tabs[i].name
            })
        }else{
            chilArr = []
            chilArr.push({
                path: tabs[i].path,
                name: tabs[i].name
            })
        }
        if(tabs[i].path == path){
            return chilArr && chilArr.length ? breadCrumbArr.concat(chilArr) : breadCrumbArr
        }
        if(tabs[i].children.length){
            // 存在子，进行递归查找
            const arr = loopSearchArr(tabs[i].children, path, breadCrumbArr, false, [])
            if(arr){
                return arr
            }
        }
    }
}

// 递归映射路由path:name对象
export const loopSearch = (tabs, breadCrumbObj, type) => {
    for(var i in tabs){
        // 不存在子，则为路由，可进行跳转
        breadCrumbObj[tabs[i].path] = tabs[i].name
        if(tabs[i].children.length){
            // 存在子，进行递归查找
            loopSearch(tabs[i].children, breadCrumbObj)
        }
    }
    if(type){
        return breadCrumbObj
    }
}

// 递归查询菜单第一个路由
export const searchFirstPath = (menu) => {
    const c = menu.children
    return c.length ?  searchFirstPath(c[0]) : menu.path
}